package com.team8.system.service.service;

import com.team8.system.pojo.DicCode;
import com.team8.system.service.dao.DicCodeDao;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Service
public class DicCodeService {

    @Autowired
    private DicCodeDao dicCodeDao;

    public List<DicCode> selectDicCodeService(String tcc, String fcc, String name){

        Example example = new Example(DicCode.class);
        Example.Criteria criteria = example.createCriteria();

        if(!StringUtils.isBlank(tcc))
            criteria.orEqualTo("threeCharacterCode", tcc);
        if(!StringUtils.isBlank(fcc))
            criteria.orEqualTo("fourCharacterCode", fcc);

        if(!StringUtils.isBlank(name))
            criteria.orLike("name", "%"+name+"%");

        List<DicCode> dicCodes = dicCodeDao.selectByExample(example);

        return dicCodes;


    }

    public List<DicCode> selecAlltDicCode() {

        List<DicCode> dicCodes = dicCodeDao.selectAll();
        return dicCodes;

    }

    public List<DicCode> selectDicCodeService(String tcc) {
        Example example = new Example(DicCode.class);
        Example.Criteria criteria = example.createCriteria();

        criteria.andEqualTo("threeCharacterCode", tcc);

        return dicCodeDao.selectByExample(example);

    }
}
